package org.huang.sample08.demo2;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

/**
 * @描述：
 * @作者: Mr.huang
 * @创建时间: 2017/8/21 12:00
 * @版本: 1.0
 */
@Service
public class PersonService {

    @Autowired
    private JdbcTemplate jdbcTemplate;


    public List<Person> list(){
        return  jdbcTemplate.query("select * from t_person", new RowMapper<Person>() {

            @Override
            public Person mapRow(ResultSet rs, int i) throws SQLException {
                Person stu = new Person();
                stu.setId(rs.getInt("id"));
                stu.setAge(rs.getInt("age"));
                stu.setName(rs.getString("name"));
                stu.setBirth(rs.getDate("birth"));
                return stu;
            }
        });
    }

}
